<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>更新密码</title>
    <link rel="stylesheet" href="../../../static/web/layui/css/layui.css" th:href="@{/web/layui/css/layui.css}" />
    <link rel="stylesheet" href="../../../static/web/kitadmin/css/ztree/metro/ztree.css" th:href="@{/web/kitadmin/css/ztree/metro/ztree.css}" />
    <link rel="stylesheet" href="../../../static/web/kitadmin/css/treeselect.css" th:href="@{/web/kitadmin/css/treeselect.css}" />


    <script src="../../../static/web/layui/layui.js" th:src="@{/web/layui/layui.js}"></script>
    <script src="../../../static/web/jquery-3.3.1/jquery-3.3.1.js" th:src="@{/web/jquery-3.3.1/jquery-3.3.1.js}"></script>
    <script src="../../../static/web/kitadmin/js/common.js" th:src="@{/web/kitadmin/js/common.js}"></script>
</head>

<body>
<form class="layui-form layui-form-pane " style="margin-left: 20px;">
    <input th:value="${user.id}" type="hidden" name="id">
    <div style="width:100%;height:300px;overflow: auto;">
        <div class="layui-form-item">
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
                <legend style="font-size:20px;font-weight: bold" th:text="'修改账户: ' + ${user.username}"></legend>
            </fieldset>
        </div>
        <div class="layui-form-item">
            <label for="password" class="layui-form-label">
                <span style="color: red">*</span>原密码
            </label>
            <div class="layui-input-inline">
                <input type="password"  id="password" name="password"  lay-verify="required|pass" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="newPassword" class="layui-form-label">
                <span style="color: red">*</span>新密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="newPassword" name="newPassword" lay-verify="required|newPass"  autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="reNewPassword" class="layui-form-label">
                <span style="color: red">*</span>确认密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="reNewPassword" name="reNewPassword"  lay-verify="required|reNewPass" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div style="width: 100%;height: 55px;background-color: white;border-top:1px solid #e6e6e6;position: fixed;bottom: 1px;margin-left:-20px;">
        <div class="layui-form-item" style=" float: right;margin-right: 30px;margin-top: 8px">
            <button  class="layui-btn " lay-filter="add" lay-submit style=" height:38px;line-hight:38px;">
                <i class="layui-icon layui-icon-ok-circle" style="vertical-align: middle"></i> 保存
            </button>
            <button  class="layui-btn layui-btn-primary" id="close" style=" height:38px;line-hight:38px;">
                <i class="layui-icon layui-icon-close-fill" style="vertical-align: middle"></i> 取消
            </button>
        </div>
    </div>
</form>


<script  type="text/javascript" th:inline="javascript">



    $(function(){
        layui.use(['form','layer'], function(){
            var form = layui.form;
            var layer = layui.layer;

            //自定义验证规则
            form.verify({
                newPassword: [
                    /(.+){6,12}$/, '密码必须6到12位'
                ]
                ,reNewPassword: function(value){
                    if($('#newPassword').val()!=$('#reNewPassword').val()){
                        return '两次密码不一致';
                    }
                    if($('#password').val()==$('#newPassword').val()){
                        return '原密码与新密码相同';
                    }
                }
            });

            $('#close').click(function(){
                closeWindow(window.name);
            });
            //监听提交
            form.on('submit(add)', function(data){
                $.ajax({
                    url:'/webs/user/doChangePassword',
                    type:'post',
                    data:data.field,
                    async:false,
                    dataType: "json",
                    traditional: true,
                    success:function(data){
                        if(data.code == 'SUCCESS'){
                            window.parent.userListTable.reload();
                            closeWindow(window.name);
                            window.top.layer.msg("更新成功！",{icon:6,offset: 'rb',area:['200px','80px'],anim:2});
                        }else{
                            window.top.layer.msg(data.message,{icon: 5});
                        }
                    },error:function(e){
                        window.top.layer.alert("发生错误！", {icon: 6},function () {
                            closeWindow(window.name);
                        });
                    }
                });
                return false;
            });
            form.render();
        });
    });



</script>
</body>

</html>
